package com.dream.demo.service.impl;

import com.dream.demo.common.ResultCommon;
import com.dream.demo.common.ResultEnum;
import com.dream.demo.dao.UserMapper;
import com.dream.demo.pojo.User;
import com.dream.demo.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
   private UserMapper userMapper;
    @Override
    public ResultCommon queryAllUser() {
        List<User> users = userMapper.queryAllUser();
        return ResultCommon.success(users);
    }

    @Override
    public ResultCommon updateUser(User user) {
        int i = userMapper.updateUser(user);
        if (i>0){
            //操作成功
            return ResultCommon.success(ResultEnum.SUCCESS);
        }
            //操作失败
            return ResultCommon.success(ResultEnum.FAIL);
    }

    @Override
    public ResultCommon deleteUserById(int id) {
        int i = userMapper.deleteUserById(id);
        if (i>0){
            //操作成功
            return ResultCommon.success(ResultEnum.SUCCESS);
        }
            //操作失败
            return ResultCommon.success(ResultEnum.FAIL);
    }

    @Override
    public ResultCommon insertUser(User user) {
        int i = userMapper.insertUser(user);
        if (i>0){
            //操作成功
            return ResultCommon.success(ResultEnum.SUCCESS);
        }
            //操作失败
            return ResultCommon.success(ResultEnum.FAIL);
    }
}
